<template>
	<view class="record-pages" :style="{background:pageColor}" v-if="isLoad">
		<fixed>
			<view class="pt-md pb-md fill-base">
				<tab @change="handerTabChange" :list="tabList" :activeIndex="activeIndex*1" bgColor="transparent" lineClass="mini"
					:activeColor="primaryColor" height="64rpx" width="33%" :textBold="true" activeTextFontSize="30rpx" textFontSize="30rpx"></tab>
			</view>
		</fixed>
		<view class="pt-md pl-md pr-md">
			<block v-for="(item,index) in list.data" :key="index">
				<longbingbingPartnerListItem :info="item" :itemIndex="index" type="record" @see="toSee" @cancel="cancel"></longbingbingPartnerListItem>
			</block>
		</view>
		<load-more :noMore="list.current_page >= list.last_page && list.data.length > 0" :loading="loading">
		</load-more>
		<abnor v-if="!loading && list.data.length <= 0 && list.current_page == 1" :isCenter="true"></abnor>
		<uni-popup ref="show_tips" type="center" :maskClick="false">
			<view class="common-popup-content fill-base pd-lg radius-34">
				<view class="title">说明</view>
				<view class="f-desc c-title mt-lg pre-wrap">
					{{tips || '暂无驳回原因'}}
				</view>
				<view class="button">
					<view @tap.stop="$refs.show_tips.close()" class="item-child c-base"
						:style="{background: primaryColor,color:'#fff'}">知道了</view>
				</view>
			</view>
		</uni-popup>
		<view class="space-footer"></view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	import longbingbingPartnerListItem from "@/components/longbingbing-partner-list-item.vue"
	export default {
		components: {
			longbingbingPartnerListItem
		},
		data() {
			return {
				options: {},
				isLoad: false,
				loading: true,
				tabList: [
					{title: '全部', id: 0},
					{title: '我发起的', id: 1},
					{title: '我报名的', id: 2}
				],
				activeIndex: 0,
				param: {
					page: 1,
					type: 0
				},
				list: {
					data: []
				},
				tips: ''
			}
		},
		computed: mapState({
			configInfo: state => state.config.configInfo,
		}),
		onLoad(options) {
			this.options = options
			this.$util.showLoading()
			this.initIndex()
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.list.current_page >= this.list.last_page || this.loading) return;
			this.param.page = this.param.page + 1;
			this.loading = true;
			this.getList();
		},
		methods: {
			...mapActions(['getConfigInfo', 'getUserInfo']),
			...mapMutations(['updateUserItem']),
			async initIndex(refresh = false) {
				
				this.$util.setNavigationBarColor({
					bg: this.primaryColor
				})
				this.getList()
				// #ifdef H5
				if (!refresh) {
					this.$jweixin.hideOptionMenu()
				}
				// #endif
			},
			initRefresh() {
				this.param.page = 1
				this.initIndex(true)
			},
			toSee(data){
				this.tips = data
				this.$refs.show_tips.open()
			},
			async cancel(index){
				let [res_del, {
					confirm
				}] = await uni.showModal({
					content: `是否确认取消${this.activeIndex==2?'报名':'活动'}？`,
					confirmText: `确认`
				})
				let {
					id = 0
				} = this.list.data[index]
				if (confirm) {
					await this.$api.partner.cancel({id})
					this.$util.showToast({
						title: `取消成功`
					})
					this.list.data.splice(index, 1)
				}
			},
			async getList() {
				let {
					list: oldList,
					param,
				} = this
				let {
					id = 0
				} = this.options
				param.id = id
				let newList = await this.$api.partner.myPartner(param)
				if (this.param.page == 1) {
					this.list = newList
				} else {
					newList.data = oldList.data.concat(newList.data)
					this.list = newList
				}
				this.loading = false
				this.isLoad = true
				this.$util.hideAll()
			},
			handerTabChange(index){
				this.activeIndex = index
				this.param.type = index
				this.param.page = 1
				this.loading = true;
				this.list.data = []
				this.$util.showLoading()
				this.getList()
			},
		},
		onShareAppMessage(e) {
			console.log(e)
			let index = 0
			if(e && e.target && e.target.dataset){
				index = e.target.dataset.index || 0
			}
			let {
				id: pid = 0
			} = this.userInfo
			let {
				id,
				title,
				cover: imageUrl
			} = this.list.data[index]
			let path = `/partner/pages/detail?pid=${pid}&id=${id}`
			this.$util.log(path)
			return {
				title,
				imageUrl,
				path,
			}
		},
	}
</script>


<style lang="scss">
	.record-pages{
		
	}
</style>